package com.yinhe.module.dr;

import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.core.page.TableDataInfo;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.system.domain.YhQualityIssues;
import com.yinhe.system.service.IYhQualityIssuesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 质量问题Controller
 *
 * @author yinhe
 * @date 2022-09-24
 */
@RestController
@RequestMapping("/dr/issues")
public class DrQualityIssuesController extends BaseController
{
    @Autowired
    private IYhQualityIssuesService yhQualityIssuesService;

    /**
     * 查询质量问题列表
     */
    @PreAuthorize("@ss.hasPermi('dr:issues:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhQualityIssues yhQualityIssues)
    {
        startPage();
        List<YhQualityIssues> list = yhQualityIssuesService.selectYhQualityIssuesList(yhQualityIssues);
        return getDataTable(list);
    }

    /**
     * 导出质量问题列表
     */
    @PreAuthorize("@ss.hasPermi('dr:issues:export')")
    @Log(title = "质量问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhQualityIssues yhQualityIssues)
    {
        List<YhQualityIssues> list = yhQualityIssuesService.selectYhQualityIssuesList(yhQualityIssues);
        ExcelUtil<YhQualityIssues> util = new ExcelUtil<YhQualityIssues>(YhQualityIssues.class);
        util.exportExcel(response, list, "质量问题数据");
    }

    /**
     * 获取质量问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('dr:issues:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhQualityIssuesService.selectYhQualityIssuesById(id));
    }

    /**
     * 新增质量问题
     */
    @PreAuthorize("@ss.hasPermi('dr:issues:add')")
    @Log(title = "质量问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhQualityIssues yhQualityIssues)
    {
        return toAjax(yhQualityIssuesService.insertYhQualityIssues(yhQualityIssues));
    }

    /**
     * 修改质量问题
     */
    @PreAuthorize("@ss.hasPermi('dr:issues:edit')")
    @Log(title = "质量问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhQualityIssues yhQualityIssues)
    {
        return toAjax(yhQualityIssuesService.updateYhQualityIssues(yhQualityIssues));
    }
    /**
     * 修改质量问题进展
     */
    @PreAuthorize("@ss.hasPermi('dr:issues:progress')")
    @Log(title = "质量问题", businessType = BusinessType.UPDATE)
    @PutMapping("/progress")
    public AjaxResult editProgress(@RequestBody YhQualityIssues yhQualityIssues)
    {
        return toAjax(yhQualityIssuesService.updateYhQualityIssues(yhQualityIssues));
    }

    /**
     * 删除质量问题
     */
    @PreAuthorize("@ss.hasPermi('dr:issues:remove')")
    @Log(title = "质量问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhQualityIssuesService.deleteYhQualityIssuesByIds(ids));
    }
}
